/**
 * 报警综合分析
 */
$(function(){
	entStatistics.init();
});
var isHasData = false;
var alarmType = "";
var entStatistics = {
	totalSubsection:[],
	GlobalGpsCache1:[],
	GlobalGpsCache2:[],
	GlobalGpsCache3:[],
	GlobalGpsCache4:[],
	GlobalGpsCache5:[],
	GlobalGpsCache6:[],
	GlobalGpsCacheQc:[],
	init: function(){
		var me = this;
		me.queryType=0;
		me.initDomH();
		me.initQueryTime();
		me.initEvent();
		//加载业户下拉框
		//me.initEnterpriseList();
		//加载车辆下拉框
		//me.initVehicleList();
		me.loadAreaList();
		me.initSubDetail1();
    	me.initSubDetail2();
    	me.initSubDetail3();
    	me.initSubDetail4();
    	me.initSubDetail5();
    	me.initSubDetail6();
    	me.initSubDetailQc();
	},
	initDomH:function(){
		$("#monitorList").height("400px");
	},
    initQueryTime:function(){
    	$("#timeType").select2();
    	$("#alarmType").select2();
        var beforeDate = new Date(new Date()-86400000*1); //前一天
	    var yyyy = beforeDate.getFullYear();
	    var mm = beforeDate.getMonth();
        var preMonth = new Date(yyyy,mm,0);
        mm = preMonth.getMonth()>9?(preMonth.getMonth()+1):('0'+(preMonth.getMonth()+1));
        $("#inputDate").val(preMonth.getFullYear() + '-' + mm);
    },
	initEvent : function(){
		var me = this;
		$('.tabsHead').on('click','li',function(){
			var index = $(this).index();
			$('.tabsHead').find('li').removeClass('active');
			$(this).addClass('active');
			me.queryType = index;
			if (index==0) {
				$("#menuContQC").hide();
				$("#menuContAL").show();
			}else if (index==1) {
				$("#menuContAL").hide();
				$("#menuContQC").show();
				
			}
		});
    	$("#queryBtn").on('click',function(){
    		var	areaIds = $("#queryArea").combotree("getValues");
    		if (areaIds.length<1) {
    			global.ajaxLoading.pop('请选择区域',false,2000);
				return;
			}
    		me.initTableTitle();
    	});
    	$("#exportExcel").on('click',function(){
    		me.exportEntStatistics();
    	});
        $("#confirmExport").click(function () {
        	me.exportComfirm();
        })
    },
    loadAreaList:function(){
		$('#queryArea').combotree({
			url:appCtx + "system/common/queryAreaName.html?level="+2,
			valueField: 'id',
            textField: 'text',
            method: 'post',
            multiple:false,//是否多选
            onlyLeafCheck:true,
            editable : false,
            collapseAll : true,
            onSuccess : function(data){
            },            
            loadFilter: function(data){
            	 //data.unshift({ id: '', text: '请选择区域'});
                 return data;
    		},
    		onLoadSuccess: function (node, data) {
    			console.log(data);
    			if (data) {
    				var id = "";
    				if (data[0].children.length>0) {
    					id = data[0].children[0].id;
					}else{
						id = data[0].id;
					}
    				$("#queryArea").combotree('setValue', id);
    				$("#queryBtn").trigger("click");
				}
    			/*$('#queryArea').combotree('tree').tree("collapseAll");
    			$('#queryArea').combotree('setText','请选择所属区域')*/
         	},
    		onBeforeSelect:function(node){
    			if (!$("#queryArea").combotree("tree").tree('isLeaf', node.target)) {
                    return false;
                }
            },
		});
	},
	//处理数据
	handTrack1: function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","vehicle_count","vehicle_access_count","vehicle_access_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache1.length,data:tmpData};
    	me.GlobalGpsCache1.push(gridData); 
    },
	handTrack2: function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","vehicle_access_count","vehicle_online_count","vehicle_online_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache2.length,data:tmpData};
    	me.GlobalGpsCache2.push(gridData); 
    },
	handTrack3: function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","track_count","track_normal","data_correct_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache3.length,data:tmpData};
    	me.GlobalGpsCache3.push(gridData); 
    },
	handTrack4: function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","sum_total_time","sum_gap_time","track_complete_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache4.length,data:tmpData};
    	me.GlobalGpsCache4.push(gridData); 
    },
    handTrack5: function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","vehicle_online_count","exception_vehicle_count","position_exception_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache5.length,data:tmpData};
    	me.GlobalGpsCache5.push(gridData); 
    },
    handTrack6 : function(jsonData){
		var me = this;
    	var GlobalGridField = ["ranking","enterprise_name","check_count","reply_correct_count","reply_rate"];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCache6.length,data:tmpData};
    	me.GlobalGpsCache6.push(gridData); 
    },
    handTrackQc: function(jsonData){
		var me = this;
		var GlobalGridField = ['ranking','enterprise_name','vehicle_access_rate','vehicle_online_rate','track_complete_rate','data_correct_rate','position_exception_rate','avg_vehicle_speed_counts','avg_vehicle_tired_duration','reply_correct_avg','adas_alarm_count','score'];
    	var tmpData = [],tmpValue = null;
    	for(var i = 0; i < GlobalGridField.length; i++){
    		tmpValue = jsonData[GlobalGridField[i]];

    		if(tmpValue != undefined && tmpValue != null)
    			tmpData.push(tmpValue);
    		else
    			tmpData.push("");
    	}
    	var gridData = {id:me.GlobalGpsCacheQc.length,data:tmpData};
    	me.GlobalGpsCacheQc.push(gridData); 
    },
	initSubDetail1:function(){
		var me = this;
		var wid =$("#objTable1").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable1',
		           header:'排名,业户名称,车辆总数,车辆入网数,入网率(%)',
		           colTypes:'ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,vehicle_count,vehicle_access_count,vehicle_access_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid1 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid1.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid1.setInitWidths(initOptions.initWidths);
		me.myGrid1.setColumnIds(initOptions.code);
		me.myGrid1.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid1.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid1.setColSorting(initOptions.sort);
		me.myGrid1.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid1.enableAutoHeight(false,'auto',true);
		me.myGrid1.init();
		me.myGrid1.enablePreRendering(1000);
		me.myGrid1.enableSmartRendering(true);
		me.myGrid1.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetail2:function(){
		var me = this;
		var wid =$("#objTable2").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable2',
		           header:'排名,业户名称,车辆入网数(辆),车辆上线数(辆),上线率(%)',
		           colTypes:'ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,vehicle_access_count,vehicle_online_count,vehicle_online_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid2 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid2.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid2.setInitWidths(initOptions.initWidths);
		me.myGrid2.setColumnIds(initOptions.code);
		me.myGrid2.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid2.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid2.setColSorting(initOptions.sort);
		me.myGrid2.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid2.enableAutoHeight(false,'auto',true);
		me.myGrid2.init();
		me.myGrid2.enablePreRendering(1000);
		me.myGrid2.enableSmartRendering(true);
		me.myGrid2.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetail3:function(){
		var me = this;
		var wid =$("#objTable3").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable3',
		           header:'排名,企业名称,数据总数(条),合格数据(条),数据合格率(%)',
		           colTypes:'ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,track_count,track_normal,data_correct_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid3 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid3.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid3.setInitWidths(initOptions.initWidths);
		me.myGrid3.setColumnIds(initOptions.code);
		me.myGrid3.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid3.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid3.setColSorting(initOptions.sort);
		me.myGrid3.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid3.enableAutoHeight(false,'auto',true);
		me.myGrid3.init();
		me.myGrid3.enablePreRendering(1000);
		me.myGrid3.enableSmartRendering(true);
		me.myGrid3.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetail4:function(){
		var me = this;
		var wid =$("#objTable4").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable4',
		           header:'排名,企业名称,总时长(小时),轨迹时长(小时),车辆轨迹完整率(%)',
		           colTypes:'ro,ro,ro,ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,sum_total_time,sum_gap_time,track_complete_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid4 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid4.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid4.setInitWidths(initOptions.initWidths);
		me.myGrid4.setColumnIds(initOptions.code);
		me.myGrid4.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid4.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid4.setColSorting(initOptions.sort);
		me.myGrid4.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid4.enableAutoHeight(false,'auto',true);
		me.myGrid4.init();
		me.myGrid4.enablePreRendering(1000);
		me.myGrid4.enableSmartRendering(true);
		me.myGrid4.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetail5:function(){
		var me = this;
		var wid =$("#objTable5").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable5',
		           header:'排名,企业名称,车辆上线数(辆),车辆漂移数(辆),漂移率(%)',
		           colTypes:'ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,vehicle_online_count,exception_vehicle_count,position_exception_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid5 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid5.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid5.setInitWidths(initOptions.initWidths);
		me.myGrid5.setColumnIds(initOptions.code);
		me.myGrid5.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid5.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid5.setColSorting(initOptions.sort);
		me.myGrid5.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid5.enableAutoHeight(false,'auto',true);
		me.myGrid5.init();
		me.myGrid5.enablePreRendering(1000);
		me.myGrid5.enableSmartRendering(true);
		me.myGrid5.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetail6:function(){
		var me = this;
		var wid =$("#objTable6").width();
		var widStr = 0.1*wid+","+0.4*wid+","+0.15*wid+","+0.15*wid+","+(0.2*wid);
		var initOptions = {	// 表格配置
		           tableId:'objTable6',
		           header:'排名,企业名称,查岗数量(次),查岗回复数量(次)	,查岗回复率(%)',
		           colTypes:'ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,check_count,reply_correct_count,reply_rate',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left',
		           sort:'no,no,no,no,no'
		    	 };
		me.myGrid6 = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid6.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;"]);//列标题
		me.myGrid6.setInitWidths(initOptions.initWidths);
		me.myGrid6.setColumnIds(initOptions.code);
		me.myGrid6.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid6.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid6.setColSorting(initOptions.sort);
		me.myGrid6.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid6.enableAutoHeight(false,'auto',true);
		me.myGrid6.init();
		me.myGrid6.enablePreRendering(1000);
		me.myGrid6.enableSmartRendering(true);
		me.myGrid6.attachEvent("onRowSelect",function(id,ind){});
	},
	initSubDetailQc:function(){
		var me = this;
		var wid = $("#menuContAL").width();
		var widStr = 0.04*wid+","+0.16*wid+","+0.06*wid+","+0.06*wid+","+0.075*wid+","+0.075*wid+","+0.115*wid+","+0.095*wid+","+0.07*wid+","+0.115*wid+","+0.08*wid+","+(0.06*wid-22);
		var initOptions = {	// 表格配置
		           tableId:'monitorList',
		           header:'排名,业户名称,入网率(%),上线率(%),轨迹完整率(%),数据合格率(%),卫星定位漂移车辆率(%),平台查岗响应率(%),平均超速次数,平均疲劳驾驶时长(分钟),不规范驾驶次数,得分',
		           colTypes:'ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro',
		           code :'ranking,enterprise_name,vehicle_access_rate,vehicle_online_rate,track_complete_rate,data_correct_rate,position_exception_rate,reply_rate,avg_vehicle_speed_counts,avg_vehicle_tired_duration,adas_alarm_count,score',
		           initWidths:widStr,
		           initWidthps:widStr,
		           align:'left,left,left,left,left,left,left,left,left,left,left,left',
		           sort:'no,no,no,no,no,no,no,no,no,no,no,no'
		    	 };
		me.myGrid = new dhtmlXGridObject(initOptions.tableId);
		me.myGrid.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;",
			"text-align:left;","text-align:left;","text-align:left;","text-align:left;"]);//列标题
		me.myGrid.setInitWidths(initOptions.initWidths);
		me.myGrid.setColumnIds(initOptions.code);
		me.myGrid.setColAlign(initOptions.align);//设置列数据的水平布局
		me.myGrid.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
		me.myGrid.setColSorting(initOptions.sort);
		me.myGrid.setSkin("dhx_skyblue");//指明使用什么皮肤
		me.myGrid.enableAutoHeight(false,'auto',true);
		//index.myGrid.enableAutoHeight(false);
		me.myGrid.init();
		me.myGrid.enablePreRendering(1000);
		me.myGrid.enableSmartRendering(true);
		me.myGrid.attachEvent("onRowSelect",function(id,ind){});
	},
    initTableTitle:function(){
    	var me = this;
    	var	areaId = $("#queryArea").combotree("getValues");
    	var inputDate = $("#inputDate").val();
    	$.ajax({
    		url:appCtx+"report/entSta/queryEnterpriseSwap.html?time="+new Date().getTime(),
    		type:"post",
    		async : true,
    		cache : false,
    		data:{
    			inputDate:inputDate,
    			areaId:parseInt(areaId)
    		},
    		dataType:"json",
    		success:function(data){
            	me.GlobalGpsCache1 = [];
            	me.GlobalGpsCache2 = [];
            	me.GlobalGpsCache3 = [];
            	me.GlobalGpsCache5 = [];
            	me.GlobalGpsCache6 = [];
            	me.GlobalGpsCacheQc = [];
                if(data&&data.access&&data.online&&data.correct&&data.position){
                	//入网率
                	var len1 = data.access.length;
                	for(var i=0;i<len1;i++){
                		var row = data.access[i];
                		me.handTrack1(row);
                	}
                	GlobalGpsCacheData1 = {
                			rows: me.GlobalGpsCache1
                	};
                	me.myGrid1.parse(GlobalGpsCacheData1,"json");
                	//上线率
                	var len2 = data.online.length; 
                	for(var i=0;i<len2;i++){
                		var row = data.online[i];
                		me.handTrack2(row);
                	}
                	GlobalGpsCacheData2 = {
                			rows: me.GlobalGpsCache2
                	};
                	me.myGrid2.parse(GlobalGpsCacheData2,"json");
                	//合格率
                	var len3 = data.correct.length; 
                	for(var i=0;i<len3;i++){
                		var row = data.correct[i];
                		me.handTrack3(row);
                	}
                	GlobalGpsCacheData3 = {
                			rows: me.GlobalGpsCache3
                	};
                	me.myGrid3.parse(GlobalGpsCacheData3,"json");
/*                	//完整率
                	var len4 = data.complete.length; 
                	for(var i=0;i<len4;i++){
                		var row = data.complete[i];
                		me.handTrack4(row);
                	}
                	GlobalGpsCacheData4 = {
                			rows: me.GlobalGpsCache4
                	};
                	me.myGrid4.parse(GlobalGpsCacheData4,"json");
*/                	//飘逸率
                	var len5 = data.position.length; 
                	for(var i=0;i<len5;i++){
                		var row = data.position[i];
                		me.handTrack5(row);
                	}
                	GlobalGpsCacheData5 = {
                			rows: me.GlobalGpsCache5
                	};
                	me.myGrid5.parse(GlobalGpsCacheData5,"json");
                	//回复率
                	var len6 = data.reply.length; 
                	for(var i=0;i<len6;i++){
                		var row = data.reply[i];
                		me.handTrack6(row);
                	}
                	GlobalGpsCacheData6 = {
                			rows: me.GlobalGpsCache6
                	};
                	me.myGrid6.parse(GlobalGpsCacheData6,"json");
                	//总分排名
                	var len7 = data.score.length; 
                	for(var i=0;i<len7;i++){
                		var row = data.score[i];
                		row.ranking = i+1;
                		//row.vehicle_access_rate = Math.round((row.vehicle_access_rate)*Math.pow(10,2))/Math.pow(10,2);
                		//row.vehicle_online_rate = Math.round((row.vehicle_online_rate)*Math.pow(10,2))/Math.pow(10,2);
                		//row.track_complete_rate = Math.round((row.track_complete_rate)*Math.pow(10,2))/Math.pow(10,2);
                		//row.data_correct_rate = Math.round((row.data_correct_rate)*Math.pow(10,2))/Math.pow(10,2);
                		var sum = row.location_exception_count+row.speed_160_count+row.gpstime_exception_count+row.head_exception_count;
                		var rate = sum>0?row.location_exception_count/sum : 0;
                		var num = row.vehicle_online_count>0?(rate*row.exception_vehicle_count)/row.vehicle_online_count :0;
                		row.position_exception_rate=Math.round((num*100)*Math.pow(10,2))/Math.pow(10,2);
                		//row.avg_vehicle_speed_counts = row.avg_vehicle_speed_counts ? Math.round((row.avg_vehicle_speed_counts/60)*Math.pow(10,2))/Math.pow(10,2) :0;
                		row.reply_correct_avg = row.check_count>0 ? Math.round((100*row.location_exception_count/row.check_count)*Math.pow(10,2))/Math.pow(10,2) :0;
                		row.avg_vehicle_tired_duration = row.reply_correct_avg?parseInt(row.reply_correct_avg/60):0;
                		me.handTrackQc(row);
                	}
                	GlobalGpsCacheDataQc = {
                			rows: me.GlobalGpsCacheQc
                	};
                	me.myGrid.parse(GlobalGpsCacheDataQc,"json");
                }
                if (data&&data.access&&data.online&&data.correct&&data.position&&data.access.length>0) {
                	isHasData=true;
				}else{
                	isHasData=false;
                	//global.ajaxLoading.pop("查询无结果",false,2000);
                }
            }
    	});
    	me.initSubDetail1();
    	me.initSubDetail2();
    	me.initSubDetail3();
    	me.initSubDetail5();
    	me.initSubDetail6();
    	me.initSubDetailQc();
    	//完整率
    	$.ajax({
    		url:appCtx+"report/entSta/queryEnterpriseSwap2.html?time="+new Date().getTime(),
    		type:"post",
    		async : true,
    		cache : false,
    		data:{
    			type:1,
    			inputDate:inputDate,
    			areaId:parseInt(areaId)
    		},
    		dataType:"json",
    		success:function(data){
            	me.GlobalGpsCache4 = [];
                if(data&&data.length>0){
                	var len4 = data.length; 
                	for(var i=0;i<len4;i++){
                		var row = data[i];
                		me.handTrack4(row);
                	}
                	GlobalGpsCacheData4 = {
                			rows: me.GlobalGpsCache4
                	};
                	me.myGrid4.parse(GlobalGpsCacheData4,"json");
                }else{
                	//global.ajaxLoading.pop("查询无结果",false,2000);
                }
            }
    	});
    	me.initSubDetail4();
    },
    // 获取查询条件
    getParams: function (queryType) {
    	var me = this;
    	var date = "";
    	var timeType = $("#timeType").val();
    	if(timeType=='day'){
    		date = $("#time-day").val();
    	}else if(timeType=='week'){
    		date = $("#time-week").val();
    	}else if(timeType=='month'){
    		date = $("#time-month").val();
    	}
    	var alarmType = $("#alarmType").val();
    	var	areaIds = $("#queryArea").combotree("getValues");
    	if (areaIds.length<1) {
    		areaIds="";
		}else{
			areaIds=areaIds.join(",");
		}
    	/*var queryContent = "";
    	if (queryType==0) {
    		queryContent = $("#queryEnterpriseSel").val();
		}else if (queryType==1) {
			queryContent = $("#queryVehicleSel").val();
		}*/
        var params = [{
        	name: 'timeType',
            value: timeType
        }, {
        	name: 'queryTime',
        	value: date
        }, {
        	name: 'alarmType',
            value: alarmType
        }, {
        	name: 'queryArea',
            value: areaIds
        }, {
            name: 'queryType',
            value: queryType
        /*}, {
            name: 'queryContent',
            value: queryContent*/
        }];
        return params;
    },
    exportEntStatistics: function(){
    	if (!isHasData) {
    		global.ajaxLoading.pop("无生成数据",false,2000);
    		return;
		}
		$("#exportTitle").html("生成业户月报（Word文档）");
    	$("#exportModal").modal("show");
	},
	exportComfirm : function(){
    	var me = this;
		$("#exportModal").modal("hide");
		var	areaId = $("#queryArea").combotree("getValues");
    	var inputDate = $("#inputDate").val();
    	global.ajaxLoading.pop('正在生成,请稍后.....',false,2000);
		var param =  {
				inputDate:inputDate,
    			areaId:areaId
		};
		post(appCtx+"report/entSta/exportTableData.html",param);
    }
	
};
